package com.heng.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

// 全局响应工具类
public class ResultUtil {
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "操作成功", data);
    }

    public static <T> Result<T> success() {
        return new Result<>(200, "操作成功", null);
    }

    public static <T> Result<T> error(String msg) {
        return new Result<>(500, msg, null);
    }

    public static <T> Result<T> error(int code, String msg) {
        return new Result<>(code, msg, null);
    }

    // 响应实体
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Result<T> {
        private int code;
        private String msg;
        private T data;
    }
}
